package Year22_Month07.day02;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class 子集2 {
    List<List<Integer>> resList = new LinkedList<>();
    LinkedList<Integer> list = new LinkedList<>();

    public List<List<Integer>> subsetsWithDup(int[] nums) {
        Arrays.sort(nums);
        backstracking(nums,0);
        return resList;
    }

    public void backstracking(int nums[],int startIndex){
        resList.add(new LinkedList<>(list));
        for (int i = startIndex; i < nums.length; i++) {
            //这里就是加了一个判断，如果说前一个元素已经被判断过了，那就直接跳过就行
            //但是注意，这里是 i > 当前递归的初始下标
            if(i > startIndex && nums[i] == nums[i - 1]){
                continue;
            }
            list.add(nums[i]);
            backstracking(nums,i+1);
            list.removeLast();
        }
    }
}
